package itcz.example.pattern.create_action.prototype.deep_clone;

import java.io.*;

/**
 * @ClassName: Client
 * @Author: ITCZ
 * @Date: 2025-07-20
 * @Description:
 */
public class Client {
    public static void main(String[] args) {
//        Citation c1 = new Citation();
//        Student stu = new Student("张三", "西安");
//        c1.setStu(stu);

        // ****** 浅克隆
//
//        //复制奖状
//        Citation c2 = c1.clone();
//        //获取c2奖状所属学生对象
//        Student stu1 = c2.getStu();
//        stu1.setName("李四");
//
//        //判断stu对象和stu1对象是否是同一个对象
//        System.out.println("stu和stu1是同一个对象？" + (stu == stu1));
//
//        c1.show();
//        c2.show();


        // 深克隆
        try {

            Citation c1 = new Citation();
            Student stu = new Student("张三", "西安");
            c1.setStu(stu);

            //创建对象输出流对象
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("/Users/itcz/_temp/b.txt"));
            //将c1对象写出到文件中
            oos.writeObject(c1);
            oos.close();

            //创建对象出入流对象
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream("/Users/itcz/_temp/b.txt"));
            //读取对象
            Citation c2 = (Citation) ois.readObject();
            //获取c2奖状所属学生对象
            Student stu1 = c2.getStu();
            stu1.setName("李四");

            //判断stu对象和stu1对象是否是同一个对象
            System.out.println("stu和stu1是同一个对象？" + (stu == stu1));

            c1.show();
            c2.show();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
